package spr;


import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import spr.test.RobotTestBed;
import static org.junit.Assert.assertTrue;

/**
 * This test makes sure that RastaBot is point north, east, west, or south before movement starts.
 * 
 * @author Shaun Ramento
 */
public class TestWallMovement extends RobotTestBed {

  boolean faceNorth = false;
  boolean faceEast = false;
  boolean faceSouth = false;
  boolean faceWest = false;

  /**
   * Specifies that Fire and RastaBot are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Fire,spr.RastaBot";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * Test for every snapshot it takes to see if it moves perpendicular to the walls.
   * @param event TurnEndedEvent
   */

  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];

    double robotHeading = robot.getBodyHeading();
    double robotHeadingDegrees = Math.toDegrees(robotHeading);
    if ((robotHeadingDegrees == 0.0)) {
      faceNorth = true;
    }
    else if (robotHeadingDegrees == 90.0) {
      faceEast = true;
    }
    else if (robotHeadingDegrees == 180.0) {
      faceSouth = true;
    }
    else if (robotHeadingDegrees == 270.0) {
      faceWest = true;
    }
  }

  /**
   * Test to make sure that the robot is not facing diagonally.
   * 
   * @param event BattleCompletedEvent
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Robot has moved along North Wall.", faceNorth);
    assertTrue("Robot has moved along West Wall.", faceEast);
    assertTrue("Robot has moved along East Wall.", faceSouth);
    assertTrue("Robot has moved along South Wall.", faceWest);
  }
}
